package com.ruoyi.userr.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.userr.domain.Users;
import com.ruoyi.userr.mapper.UserUsersMapper;
import org.springframework.stereotype.Service;
import com.ruoyi.userr.mapper.PointFlowMapper;
import com.ruoyi.userr.domain.PointFlow;
import com.ruoyi.userr.service.IPointFlowService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 积分流水Service业务层处理
 * 
 * @author hy
 * @date 2025-08-17
 */

@Service("pointCoreFlowServiceImpl")
public class PointFlowServiceImpl implements IPointFlowService 
{
    @Autowired
    @Qualifier("pointModuleFlowMapper")
    private PointFlowMapper pointFlowMapper;
    @Resource
    private UserUsersMapper usersMapper;

    /**
     * 查询积分流水
     * 
     * @param id 积分流水主键
     * @return 积分流水
     */
    @Override
    public PointFlow selectPointFlowById(Integer id)
    {
        return pointFlowMapper.selectPointFlowById(id);
    }

    /**
     * 查询积分流水列表
     * 
     * @param pointFlow 积分流水
     * @return 积分流水
     */
    @Override
    public List<PointFlow> selectPointFlowList(PointFlow pointFlow)
    {
        return pointFlowMapper.selectPointFlowList(pointFlow);
    }

    /**
     * 新增积分流水
     * 
     * @param pointFlow 积分流水
     * @return 结果
     */
    @Override
    @Transactional
    public int insertPointFlow(PointFlow pointFlow)
    {

        Users users=new Users();

        users.setTotalPoint(pointFlow.getBalance());
        users.setId(pointFlow.getUserId());
        System.out.println("用户分数"+users.getTotalPoint());
        usersMapper.updateUsers(users);
        pointFlow.setCreateTime(DateUtils.getNowDate());
        return pointFlowMapper.insertPointFlow(pointFlow);
    }

    /**
     * 修改积分流水
     * 
     * @param pointFlow 积分流水
     * @return 结果
     */
    @Override
    public int updatePointFlow(PointFlow pointFlow)
    {
        return pointFlowMapper.updatePointFlow(pointFlow);
    }

    /**
     * 批量删除积分流水
     * 
     * @param ids 需要删除的积分流水主键
     * @return 结果
     */
    @Override
    public int deletePointFlowByIds(Integer[] ids)
    {
        return pointFlowMapper.deletePointFlowByIds(ids);
    }

    /**
     * 删除积分流水信息
     * 
     * @param id 积分流水主键
     * @return 结果
     */
    @Override
    public int deletePointFlowById(Integer id)
    {
        return pointFlowMapper.deletePointFlowById(id);
    }

    @Override
    public int point(PointFlow pointFlow) {
        return pointFlowMapper.point(pointFlow);
    }

}
